<!-- HTML5文件 -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
		<meta name="format-detection" content="telephone=no">
		<title>html title</title>

		<link rel="stylesheet" href="../assets/agile/css/agile.layout.css">
		<link rel="stylesheet" href="../assets/third/seedsui/plugin/seedsui/seedsui.min.css">
		<link rel="stylesheet" href="../assets/third/seedsui/plugin/animate/animate.css">
		<style>
			.titlebar,.tab.active{
				background-color:#18B2ED;
			}
			.titlebar h1,.tab.active label{
				font-weight:bold;
				color:white;
			}
			.titlebar a i,.titlebar a label{
				color:white;
			}
			.art_mid{
				top:45px;
				bottom:40px
			}
			
		</style>
	</head>
	<body>
		<div id="section_container">
		 <section id="sectionid" data-role="section" class="active">
		 	<header>
		 		<div class="titlebar" >
		 			<a class="left">
		 				<label class="bold"><i class="icon icon-arrowleft-fill"></i>登出</label>
		 			</a>
		 			<h1 class="text-center ">首页</h2>
		 			<a class="right">
		 				<i class="icon icon-menu-fill"></i>
		 			</a>
		 		</div>
		 	</header>
		 	<article id="article_main" data-role="article" data-transition="slide"  class="active art_mid" >
		 		获取文件夹下的所有文件
		 		<span class="button bg-3 block" style="margin:5px" id="getfiles">getfiles</span>
		 		<span class="button bg-4 block" style="margin:5px" id="getfiles2">getDirName</span>
		 		<span class="button bg-6 block" style="margin:5px" id="upload">upload</span>
		 		<div id="log_cont">
		 		  <div id="main_cont" data-scroll="verticle" style="height:200px">
		 		  	<div class="scroller">
		 		      <div v-for="i in list" style="padding:5px">
		 		  	  <span class="small">{{i.time}}</span><br />
		 		  	  <span class="bold" pre-wrap>{{i.msg}}</span>
		 		      </div>
		 		  	</div>
		 		  </div>
		 		</div>
		 	</article>
		 	<article id="article_serv"  data-role="article" data-transition="slide" data-scroll="verticle" class="art_mid" >
		 		<div class="scroller">
		 			pageserv
		 		</div>
		 	</article>
		 	<article id="article_conf" data-role="article" data-transition="slide" data-scroll="verticle" class="art_mid" >
		 		<div class="scroller">
		 			pageconfig
		 		</div>
		 	</article>
		 	<footer>
				<ul class="menubar" style="line-height: 40px;">
					<li class="tab active" data-role="tab" href="#article_main" data-toggle="article">
						<label class="text-center">文件</label>
					</li>
					<li class="tab " data-role="tab"  href="#article_serv" data-toggle="article">
						<label class="text-center">服务</label>
					</li>
					<li class="tab " data-role="tab"  href="#article_conf" data-toggle="article">
						<label class="text-center">设置</label>
					</li>
				</ul>
		 	</footer>
		 </section>
		</div>
		<script src="../assets/third/amd/require.js" ></script>
		<script src="../assets/app/js/app.require.js"></script>
		<script src="../assets/cgs_token/csg_util.js"></script>
		<script>
		var isbridge = false
		document.addEventListener('plusready',onPlusReady,false)
		function onPlusReady(){
			alert(1)
			isbridge  = true
		};
		var uploadsuccess,uploadfail;  
		 require(['vue','util','agile'],function(Vue,Util){
		 	$('#getfiles').on('tap',function(){
		 		if(isbridge){
		 			var filepath = 'sys:db/img2'
		 			var dir  = new File(filepath,true)
		 			var array =dir.listFiles(".*");
		 			var html  = ''
		 			for(key in array){
		 				//html+=(array[key].getFileName()+'</br>')
		 		        logVm.log(array[key].getFileName())
		 				var array2 =array[key].listFiles(".*");
		 				for(key in array2){
		 				  //html+=('--> '+array2[key].getFileName()+'</br>')
		 		          logVm.log('--> '+array2[key].getFileName())
		 				}
		 			}
		 			//$('#recal').html(html)
		 		}
		 		else{
		 			for(var i=0;i<20;i++){
		 		        logVm.log("日志测试")
		 			}
		 		}
		 	})
		 	
		 	$('#getfiles2').on('click',function(){
		 		if(isbridge){
		 			var filepath = 'sys:db/img2'
		 			var dir  = new File(filepath,true)
		 			var array =dir.list(".*");
		 			var html  = ''
		 			for(key in array){
		 				//取img之后的文件夹名称
		 				//html+=(array[key].replace(/.*img\//,"")+'</br>')
		 		        logVm.log(array[key].replace(/.*img\//,""))
		 			}
		 			//$('#recal').html(html)
		 		}
		 	})
		 	
		 	//分批上传图片
		 	$('#upload').on('click',function(){
		 		if(isbridge){
		 	        $('#recal').html('')
		 		 	var filepath = 'sys:db/img2'
		 			var dir  = new File(filepath,true)
		 			var array =dir.listFiles(".*");
		 			maininfo.total=array.length
		 			for(key in array){
		 				var tmpdata =[];
                          var iddata={};
                          iddata.type=0;
                          iddata.name="id";
                          iddata.value = array[key].getFileName();
                          tmpdata.push(iddata);
		 				var img =array[key].listFiles(".*");
		 				for(key in img){
                          var imgfile={};
                          imgfile.type=1;
                          imgfile.name="imgfile";
                          imgfile.value = img[key].getFilePath();
                          tmpdata.push(imgfile)
		 				}
		 				//以实物为单位上传图片,南网鉴权模式
		 				Cgs_token(upLoad,tmpdata);
		 			}
		 		}
		 	})
		 	
		 	var maininfo = {
		 		total:0,
		 		done:0,
		 		success:0,
		 		fail:0
		 	}
		 	
		 	var upLoad = function(token,datalist){
                var ajaxData = {};
                ajaxData.data = datalist;    
                ajaxData.method = "POST";  
                ajaxData.isBlock = true;
                ajaxData.url = "http://"+settingInfo.ip+":"+settingInfo.port+"/process/service/"+ClientUtil.getAppId()+"/"+"/uploadImg";     
                ajaxData.successFunction = "uploadsuccess";  
                ajaxData.failFunction = "uploadfail";  
                if (token.length>0){
					var requestHeader = '{"access_token":"'+token+'"}'
					ajaxData.requestHeader =  eval("(" + requestHeader + ")") 
			    }
                var ajax = new DirectFormSubmit(ajaxData);
                ajax.send();
		 	}
		 	
		 	uploadsuccess = function(data){
		 		var json = eval("("+data.responseText+")")
		 		//alert(json.msg)
		 		var flag = json.ret?1:0
		 		 logVm.log(json.msg)
		 		 countInfo(flag)
		 	}
		 	
		 	uploadfail = function(){
		 		logVm.log("上传失败")
		 		countInfo(0)
		 	}
		 	
		 	
		 	var countInfo = function(flag){
		 		if (flag==1){
		 		  maininfo.success++
		 		}else{
		 		  maininfo.fail++
		 		}
		 		maininfo.done++
		 		if (maininfo.total==maininfo.done){
		 		  logVm.log("图片上传操作完毕。成功："+maininfo.success+"  失败："+maininfo.fail)
		 		}
		 	}
		 	
		 	var logVm = new Vue({
		 		el:"#log_cont",
		 		data:{
		 			list:[]
		 		},
		 		methods:{
		 			log:function(msg){
		 				var bean = {}
		 				bean.time= new Date().dateFormat('yyyy-MM-dd hh:mm:ss') 
		 				bean.msg=msg
		 				this.list.push(bean)
		 				this.$nextTick(function(){
		 					this.refreshScroll('#main_cont')
		 				})
		 			},
		 			refreshScroll:function(id){
		 	            var Scroll = A.Scroll(id)
		 	            Scroll.refresh()
		 		        Scroll.scrollTo(0,Scroll.maxScrollY,500,false)
		 			}
		 		}
		 	})
		 	
		 });
		</script>
	</body>
</html>